using Arcane.Source.Client.Extensions;
using Arcane.Source.Combat;
using Godot;
using Godot.Collections;

namespace Arcane.Source.Client
{
    public partial class EntityApi(Entity e) : GodotObject
    {
        public float Health => e.Health;
        public float MaxHealth => e.maxHealth;

        public void Hurt(float damage) => e.Hurt(DamageType.Common, damage);
        public void MagicalHurt(float damage) => e.Hurt(DamageType.Magical, damage);
        public void Attack(int target, float damage) => e.Attack(e.GetTarget(target), DamageType.Common, damage);
        public void MagicalAttack(int target, float damage) => e.Attack(e.GetTarget(target), DamageType.Magical, damage);
        public void Charge(float value) => e.Charge(value);

        public void AddStatusEffect(int target, StringName effectName, StringName triggerName, Array variants)
        {
            e.AddStatusEffect(target, true, effectName, triggerName, [.. variants]);
        }

        public void AddInvisibleEffect(int target, StringName effectName, StringName triggerName, Array variants)
        {
            e.AddStatusEffect(target, false, effectName, triggerName, [.. variants]);
        }
        
        public void AddModifier(StringName name, Dictionary modifier)
        {
            if (modifier.TryCastModifier(out var m))
            {
                e.AddModifier(name, m);
            }
        }
        public void RemoveModifier(StringName name) => e.RemoveModifier(name);

        public Variant GetMeta(StringName name) => e.GetMeta(name).Value.ToVariant();
    }
}